package com.lagou.service.impl;

import com.lagou.pojo.Article;
import com.lagou.repository.ArticleRepository;
import com.lagou.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

@Service
@Transactional
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleRepository articleRepository;


    @Override
    public Page<Article> findListByPage(int page,int size) {
        Sort sort = Sort.by(Sort.Direction.DESC, "id");
        Page<Article> pageList = articleRepository.findAll(PageRequest.of(page,size,sort));
        return pageList;
    }
}
